#include "engine.h"
#include "internal_types.h"

#include <list>
using namespace std;

namespace HW
{

list<TWorld> lWorlds;

TWorld CreateWorld(void)
{
	_i_World* world = new _i_World;

	lWorlds.push_back ( TWorld(world) );

	SetWorld ( TWorld(world) );

	return TWorld(world);
}

void SetWorld(TWorld world)
{
	extern TWorld gCurrWorld;
	gCurrWorld = world;
}

void SetWorldSize(const TVec3 &size)
{
	extern TWorld gCurrWorld;
	((_i_World*)(gCurrWorld))->size = size;
}

void SetWorldCullRange(flt nearrange, flt mediumrange, flt farrange)
{
	extern TWorld gCurrWorld;
	((_i_World*)(gCurrWorld))->range.X = nearrange;
	((_i_World*)(gCurrWorld))->range.Y = mediumrange;
	((_i_World*)(gCurrWorld))->range.Z = farrange;
}

void ClearWorld(void)
{
}

void FreeWorld(TWorld world)
{
	TWorld lCurrWorld = CurrentWorld();
	if ( lCurrWorld == world )
		lCurrWorld = NULL;

	SetWorld ( world );
	ClearWorld ( );

	SetWorld ( lCurrWorld );

	for ( list<TWorld>::const_iterator it = lWorlds.begin() ; it != lWorlds.end() ; ++it )
	{
		if ( *it == world )
			lWorlds.erase ( it );
	}

	delete world;
}

TWorld CurrentWorld(void)
{
	extern TWorld gCurrWorld;
	return gCurrWorld;
}

void UpdateWorld(float stepsize)
{
}

void RenderWorld(int elements)
{
}

TEntity LoadScene(const_str name)
{
	return 0;
}

}